<?php

namespace app\api\controller;

use think\Controller;
use think\Db;
use think\Config;
use think\Request;

class Login  extends  Controller
{
    //登录
    public function login($code, $tel,$password)
    {
        $captcha = new \think\captcha\Captcha();

        if(empty($code) || ! $captcha->check($code)){
            return result(500,'验证码错误，请重新输入！');
        }
        
        $userInfo = Db::name('user')->where(['tel'=>$tel,'password'=>$password])->find();
        if(!empty($userInfo))
        {
            session('user',$userInfo);
            return result(200,'登录成功！');
        }else{
            return result(500,'账号密码不匹配！');
        }
    }
    //退出登录
    public function logout()
    {
        session('user',null);
        return result(200,'退出成功！');
    }
}